package cn.school.controller.notice;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.notice.dao.WorkflowNoticeDao;
import cn.school.notice.entity.WorkflowNotice;
import cn.school.notice.service.WorkflowNoticeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "t_workflow_notice => 流程审批通知表")
@RequestMapping("/notice")
public class WorkflowNoticeController {

    @Autowired
    private WorkflowNoticeService tripWorkflowNoticeService;

    @Autowired
    WorkflowNoticeDao workflowNoticeDao;

    @ApiOperation("getNotice => 查询流程审批通知表")
    @PostMapping("/getNotice")
    public CommonResult<List<WorkflowNotice>> getNotice() {
        List<WorkflowNotice> tripWorkflowNotices = tripWorkflowNoticeService.selectById();
        return CommonResult.success(tripWorkflowNotices);
    }

    @ApiOperation("addNotice => 新增流程审批通知表")
    @PostMapping("/addNotice")
    public CommonResult<Integer> addNotice(@RequestBody WorkflowNotice tripWorkflowNotice) {
        int insert = tripWorkflowNoticeService.insert(tripWorkflowNotice);
        if (insert > 0) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("deleteNotice => 删除流程审批通知表")
    @PostMapping("/deleteNotice")
    public CommonResult<Integer> deleteNotice(@RequestBody WorkflowNotice tripWorkflowNotice) {
        int num = tripWorkflowNoticeService.deleteNotice(tripWorkflowNotice);
        if (num > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("updateNotice => 修改流程审批通知表")
    @PostMapping("/updateNotice")
    public CommonResult<Integer> updateNotice(@RequestBody WorkflowNotice tripWorkflowNotice) {
        int num = tripWorkflowNoticeService.update(tripWorkflowNotice);
        if (num > 0) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @ApiOperation("findNoticePageList => 分页查询流程审批通知表")
    @PostMapping(value = "/findNoticePageList")
    public CommonResult<CommonPage<WorkflowNotice>> findBaseSpaceLocationPageList(@RequestBody WorkflowNotice workflowNotice) {
        IPage<WorkflowNotice> noticePageList = tripWorkflowNoticeService.findNoticePageList(workflowNotice);
        return CommonResult.success(CommonPage.restPage(noticePageList));
    }
}
